<?php

namespace app\controller;

use app\BaseController;
use app\Request;
use app\services\CustomerService;
use app\utils\AppRespUtil;

class Customer extends BaseController
{

    public function customerList(Request $request)
    {
        $params = $request->only(['page', 'page_size', 'keywords'], 'post');
        $this->validate(
            $params,
            [
                'page' => 'integer|gt:0',
                'page_size' => 'integer|gt:0',
            ],
            [
                'page.integer' => '请选择正确的页码',
                'page.gt' => '请选择正确的页码',
                'page_size.integer' => '每页条数必须大于0',
                'page_size.gt' => '每页条数必须大于0',
            ]
        );
        return AppRespUtil::success((new CustomerService($request->userInfo, $params))->customerList());
    }

    public function customerInfo(Request $request)
    {
        $params = $request->post();
        (new CustomerService([], $params))->customerInfo();
        return AppRespUtil::success((new CustomerService($request->userInfo, $params))->customerInfo());
    }

    public function createCustomer(Request $request)
    {
        $params = $request->post();
        (new CustomerService($request->userInfo, $params))->createCustomer();
        return AppRespUtil::success();
    }

    public function saveCustomer(Request $request)
    {
        $params = $request->post();
        (new CustomerService($request->userInfo, $params))->saveCustomer();
        return AppRespUtil::success();
    }

}